package com.able.concurrency.t1;

import java.util.concurrent.TimeUnit;

/**
 * @author abel.he
 * @data 2018/8/15 19:12
 * @describe 锁可重入。同一线程，多次调用同步代码，锁定同一个所对象，可重入
 */
public class Test6 {

    synchronized void m1() {
        System.out.println("m1 start");
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        m2();
        System.out.println("m1 end");
    }

    private synchronized void m2() {
        System.out.println("m2 start");
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("m2 end");
    }

    public static void main(String[] args) {
        new Test6().m1();
    }

}
